﻿using BenCaoXuan.Infrastructure.Attr;
using BenCaoXuan.Infrastructure.Dto;
using BenCaoXuan.Infrastructure.Dto.Admin.product;
using BenCaoXuan.Service.Interface.admin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BenCaoXuan.Api.Admin.Controllers.admin
{
    [ApiGroup("Admin(管理端模块)")]
   
    public class ProductController : BaseController
    {
        private readonly I_Product_Service _product_Service;

        public ProductController(I_Login_Service login_Service, I_Product_Service product_Service) : base(login_Service)
        {
            _product_Service = product_Service;
        }



        /// <summary>
        /// 管理端-查看所有产品
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Product(int page=1,int limit=10,string? key="") 
        {
            var result = await _product_Service.Get_Product(new Fenye_Dto() { 
            page=page, limit=limit, key=key??""
            });
            return Ok(result);
        }

  

        /// <summary>
        /// 管理端-编辑产品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_Product(UpdateProduct_Dto dto)
        {
            var result = await _product_Service.Update_Product(dto);
            return Ok(result);
        }


        /// <summary>
        /// 管理端-删除产品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Product(Delete_Dto dto) {
            var result = await _product_Service.Delete_Product(dto);
                return Ok(result);
        }

        /// <summary>
        /// 管理员-切换产品的状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangeIsBan_Product(IsBan_Dto dto) {
            var result = await _product_Service.ChangeIsBan_Product(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-新增产品
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Product(AddProduct_Dto dto) {
            var result = await _product_Service.Add_Product(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取所有的产品套餐可选的产品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_ProductPackageBy_Product() {
            var result = await _product_Service.Get_ProductPackageBy_Product();
            return Ok(result);
        }

        /// <summary>
        /// 管理端-创建产品套餐
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_ProductPackage(AddProductPackage_Dto dto)
        {
            var result = await _product_Service.Add_ProductPackage(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取所有产品套餐
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="isBan"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_ProductPackage(int page=1,int limit=10,string? isBan="",string? key="") {
            var result = await _product_Service.Get_ProductPackage(new Fenye_Dto() { 
            page=page,
            limit=limit,
            key=key??"",
            isBan=isBan??"",
            });
            return Ok(result);
        }

        /// <summary>
        /// 管理端-编辑产品套餐
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_ProductPackage(UpdateProfuctPackage_Dto dto) {
            var result = await _product_Service.Update_ProductPackage(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-切换产品套餐的状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangeIsBan_ProductPackage(IsBan_Dto dto) {
            var result = await _product_Service.ChangeIsBan_ProductPackage(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-新增产品的文章
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_ProductArticle(AddProductArticle_Dto dto) {
            var result = await _product_Service.Add_ProductArticle(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取所有的产品文章
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_ProductArticle(int page=1,int limit=5,string? key="") {
            var result = await _product_Service.Get_ProductArticle(new Fenye_Dto() { 
            page = page,
            limit = limit,
            key = key??""
            });
            return Ok(result);


        }

        /// <summary>
        /// 管理端-切换产品文章的发布下架
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangeIsPublish_ProductPackage(IsBan_Dto dto) {
            var result = await _product_Service.ChangeIsPublish_ProductPackage(dto);
            return Ok(result);
        }



        /// <summary>
        /// 管理端-停止套餐
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Stop_ProductPackage(IsBan_Dto dto) {
            var result = await _product_Service.Stop_ProductPackage(dto.id);
            return Ok(result);
        }
    }
}
